#!/usr/bin/env bash

SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
NODE_PATH="${SCRIPT_PATH}/flipper-runtime"
SERVER_RESOURCES="$SCRIPT_PATH/../Resources/server"

cd "$SERVER_RESOURCES" || exit 1
echo "Starting flipper-server ..."
"$NODE_PATH" . "$@" &

# Wait for the Flipper HTTP server to start listening
while ! curl -s http://localhost:52342 >/dev/null; do
    sleep 1
done
